﻿using BasicData.API.Read.Application.Commands;
using BasicData.Domain;
using BasicData.ErrorCode;
using BasicData.Infrastructure.interfaces;
using MediatR;

namespace BasicData.API.Read.Application.CommandHandlers
{
    
    public class GetChanCommandHandler : IRequestHandler<GetChanCommand, APIResult<List<ChanModel>>>
    {
        private readonly IBaseRepository<ChanModel> baseRepository;

        public GetChanCommandHandler(IBaseRepository<ChanModel> baseRepository)
        {
            this.baseRepository = baseRepository;
        }

        public async Task<APIResult<List<ChanModel>>> Handle(GetChanCommand request, CancellationToken cancellationToken)
        {
            var list = baseRepository.GetAll();
          
                list = list.Where(x => x.GoodsId == request.GoodsId);
            
            
            return APIResult<List<ChanModel>>.Success("显示成功", list.ToList());
        }
    }
}
